import { defineStore } from 'pinia';

import request from '@/utils/request'
import { GoodsInfo } from '@/types/goods'
import { ApiResponse } from '@/types/data';

export default defineStore('goods', {
  state() {
    return {
      info: {} as GoodsInfo,
    }
  },
  getters: {},
  // 获取商品详情
  actions: {
    async fetchGoodsInfo(id: string) {
      try {
        const res = await request.get<ApiResponse<GoodsInfo>>('/goods', {
          params: { id }
        })
        if (res.data.result) {
          this.info = res.data.result
        }
      } catch (error) {
        console.error(error);
      }
    }
  },

})
